<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="800px"
    @close="() => (dialogFormVisible = false)"
  >
    <el-descriptions
      ref="form"
      class="margin-top"
      title="开发商信息"
      :column="2"
      border
      :model="form"
    >
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-user"></i>
          真实姓名
        </template>
        <el-tag size="small">{{ form.userName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-phone-outline"></i>
          手机号码
        </template>
        <el-tag size="small">{{ form.phone }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-c-scale-to-original"></i>
          地产名称
        </template>
        <el-tag size="small">{{ form.businessEstateName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-office-building"></i>
          项目名称
        </template>
        <el-tag size="small">{{ form.projectName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-time"></i>
          创建日期
        </template>
        <el-tag size="small" type="info">{{ form.createTime }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-time"></i>
          更新日期
        </template>
        <el-tag size="small">{{ form.updateTime }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          当下状态
        </template>
        <el-tag
          size="small"
          :type="
            form.status == 2
              ? 'success'
              : form.status == 3
              ? 'danger'
              : form.status == 1
              ? 'info'
              : 'warning'
          "
        >
          {{ getValue(form.status) }}
        </el-tag>
      </el-descriptions-item>
    </el-descriptions>
    <div slot="footer" class="dialog-footer">
      <el-button
        v-if="form.status == 1"
        type="danger"
        size="small"
        @click="confirm(true)"
      >
        不通过审核
      </el-button>
      <el-button
        v-if="form.status == 1"
        type="primary"
        size="small"
        @click="confirm(false)"
      >
        通过审核
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { updateStatus } from '@/api/user'
  import { parseTime } from '@/utils/index'
  import _ from 'lodash'
  export default {
    name: 'CheckDeveloper',
    data() {
      return {
        setStatus: {},
        form: {},
        title: '',
        dialogFormVisible: false,
      }
    },
    methods: {
      getValue(value) {
        switch (value) {
          case 1:
            return '未审核'
          case 2:
            return '已通过'
          case 3:
            return '未通过'
        }
      },
      showEdit(row) {
        this.title = '审核开发商信息'
        this.setStatus = row
        this.form = _.cloneDeep(row)
        this.dialogFormVisible = true
      },
      close() {
        this.dialogFormVisible = false
        this.$emit('fetch-data')
      },
      async confirm(value) {
        let _form = {}
        _form.status = value ? 3 : 2
        _form.id = this.form.id
        const time = new Date()
        _form.updateTime = parseTime(time)
        const { data } = await updateStatus(_form)
        console.log(data)
        if (data.status === 0) {
          this.dialogFormVisible = false
          this.setStatus.status = 2
          this.$emit('fetch-data')
        } else {
          this.setStatus.status = 3
          if (value) {
            this.$emit('fetch-data')
            this.dialogFormVisible = false
          } else {
            this.$baseMessage(data.message, 'error')
          }
        }
      },
    },
  }
</script>
